package com.tj.api.rest.user.request;

import com.fqgj.common.api.ParamsObject;
import com.fqgj.common.utils.StringUtils;
import com.tj.bo.common.conf.util.EmailUtils;
import com.tj.bo.common.conf.util.MobileUtils;
import com.tj.bo.common.conf.util.ParamsValidateUtil;
import org.hibernate.validator.constraints.Length;

/**
 * @program: binary-option
 * @description
 * @author: frank
 * @create: 2020-09-02 12:02
 **/
public class UserAuthRequest extends ParamsObject {

    @Length(min = 3, max = 32, message = "The length of the name must be between 3 and 32 bits")
    private String name;
    private String email;
    private String mobile;

    public String getName() {
        return name;
    }

    public UserAuthRequest setName(String name) {
        this.name = name;
        return this;
    }

    public String getEmail() {
        return email;
    }

    public UserAuthRequest setEmail(String email) {
        this.email = email;
        return this;
    }

    public String getMobile() {
        return mobile;
    }

    public UserAuthRequest setMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }

    @Override
    public void validate() {
        ParamsValidateUtil.checkParams(StringUtils.isEmpty(name), "name can not be empty");
        ParamsValidateUtil.checkParams(StringUtils.isEmpty(email), "email can not be empty");
        ParamsValidateUtil.checkParams(!EmailUtils.isEmail(email), "Please enter the valid email");
        ParamsValidateUtil.checkParams(StringUtils.isEmpty(mobile), "phone number cannot be empty");
        mobile = MobileUtils.removeExcess(mobile);
        ParamsValidateUtil.checkParams(!MobileUtils.isIndiaMobile(mobile), "phone number is invalid");
    }
}
